<template>
  <SlideSelect ref="vSlideSelect"/>
</template>

<script>
import SlideSelect from '../slide-select/SlideSelect'
import DateHandle from './date-handle'
export default {
  created () {
    this.dateHandle = new DateHandle()
  },
  methods: {
    show () {
      let {dateHandle} = this
      // 设置年范围
      dateHandle.setYearRange(2017, 2022)
      // 生成指定年月数据
      let dateData = dateHandle.getDataWeek(new Date('2018/1/1'))
      this.$refs.vSlideSelect.show({
        // titles: ['开始时间', '结束时间'],
        lists: dateData,
        // selectedIndexs: [0, 0, 0], // 指定选择，通过重新赋值控制子组件选择
        selectedValues: [2018, 1, 20], // 指定选择
        onChange (index, id, selectedIndexs) {
          // 联动
          if (id < 2) {
            let {years, months} = dateHandle
            let year = years[selectedIndexs[0]].value
            let month = months[selectedIndexs[1]].value
            this.setList(2, dateHandle.getDayDataWeek(year, month))
          }
        },
        onConfirm (selectedValues) {
          return false // 可阻止关闭
        }
      })
    }
  },
  components: {
    SlideSelect
  }
}
</script>

